package cc.mrbird.common.domin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;

public class ResponseBo extends HashMap<String, Object> {

	private static final long serialVersionUID = -8713837118340960775L;

	// 成功
	private static final Integer SUCCESS = 0;
	// 警告
	private static final Integer WARN = 1;
	// 异常 失败
	private static final Integer FAIL = 500;

	public ResponseBo() {
		put("code", SUCCESS);
		put("msg", "操作成功");
		put("data", null);
	}

	public static ResponseBo error() {
		ResponseBo responseBo = new ResponseBo();
		responseBo.put("code", FAIL);
		responseBo.put("msg", "操作失败，请联系管理员");
		responseBo.put("data", null);
		return responseBo;
	}

	public static ResponseBo warn(int count) {
		ResponseBo responseBo = new ResponseBo();
		responseBo.put("code", WARN);
		responseBo.put("msg", "操作失败，请联系管理员");
		responseBo.put("data", null);
		return responseBo;
	}

	public static ResponseBo ok(Object data) {
		ResponseBo responseBo = new ResponseBo();
		responseBo.put("code", SUCCESS);
		responseBo.put("msg", "操作成功");
		responseBo.put("data", data);
		return responseBo;
	}

	public static ResponseBo ok() {
		ResponseBo responseBo = new ResponseBo();
		responseBo.put("code", SUCCESS);
		responseBo.put("msg", "操作成功");
		responseBo.put("data", null);
		return responseBo;
	}

	public static ResponseBo ok(int count) {
		return count>0?ok():warn(count);
	}

	public static ResponseBo operationDetail(Page t) {
		ResponseBo responseBo = new ResponseBo();
		responseBo.put("code", SUCCESS);
		responseBo.put("msg", "操作成功");
		responseBo.put("total",t.getTotal());
		responseBo.put("pageSize",t.getSize());
		responseBo.put("pageNum",t.getCurrent());
		responseBo.put("pageCount",t.getPages());
		responseBo.put("data", t.getRecords());
		return responseBo;
	}

	@Override
	public ResponseBo put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
